import myComponent from '../alert/alert.vue'

export default {
    data () {
        return {
            gid: this.$route.params.gid,
            image: '',
            name: '',
            num: '',
        }
    },
    mounted() {
        this.loading();
        window.scrollTo(0,0);
    },
    components: {
        myComponent
    },
    methods: {
        loading(){
            var _this = this;
            _this.$http.post('/index.php?s=/EyesDsj/json4user',{id:_this.gid}).then(function(res){
                var data = res.data.data;
                _this.image = data.imageurl;
                _this.name = data.name;
                _this.num = data.votecount;
            });
        },
        //投票
        vote(){
            var _this = this;
            _this.$http.post('/index.php?s=/EyesDsj/vote',{id:_this.gid}).then(function(res){
                var data = res.data;
                _this.$refs.alerts.showalert(data.errmsg, '谢谢您的参与');
                if(data.errmsg == '投票成功'){
                    _this.num = parseInt(_this.num) + 1;
                }
            });
        }
    }
}
